<?php

function fffcontains($substring, $string) {
        $pos = strpos($string, $substring);
 
        if($pos === false) {
                // string needle NOT found in haystack
                return false;
        }
        else {
                // string needle found in haystack
                return true;
        }
 
}



$arr = array();
$q = "qqq";
if(isset($_GET["q"])) {
    $q = $_GET["q"];
}

$i = 0;
while($i < 10) {
	$item = array(
		"id"  => $i,
		"name" => "name" . $i
	);
	$i++;
	
    $arr[] = $item;
}

//search
$arrRS = array();
$i = 0;
while($i < count($arr)) {	
    if(fffcontains($q, $arr[$i]["name"])) {
		$arrRS[] = $arr[$i];		
	}
	
	$i++;
}


# JSON-encode the response
$json_response = json_encode($arrRS);

# Optionally: Wrap the response in a callback function for JSONP cross-domain support
if(isset($_GET["callback"])) {
    $json_response = $_GET["callback"] . "(" . $json_response . ")";
}

# Return the response
echo $json_response;

?>